﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Globalization;
using System.Web.UI;

namespace Terralever.Facebook.UI.FbmlControls
{
    /// <summary>
    /// Displays content inside the tag only if the logged-in user (or specified user) is an application user.
    /// </summary>
    /// <remarks>
    /// <para>The Facebook documentation for the rendered control can be found 
    /// <a href="http://wiki.developers.facebook.com/index.php/Fb:if-is-app-user" target="_blank">here</a>.</para>
    /// </remarks>
    [ToolboxData("<{0}:IfIsAppUser runat=\"server\"></{0}:IfIsAppUser>")]
    [DefaultProperty("UserID")]
    public class IfIsAppUser : LogicTestControl
    {
        /// <summary>
        /// Gets or sets an optional user ID to check; if this value is not set, it will check the logged-in user.
        /// </summary>
        [Browsable(true)]
        [Category(FbmlConstants.FBML_OPT_ATTR)]
        [Description("The user ID to check.")]
        [DefaultValue(0)]
        public long UserID
        {
            get;
            set;
        }

        /// <inheritdoc />
        protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);

            if (UserID != 0)
                writer.AddAttribute("uid", UserID.ToString(CultureInfo.InvariantCulture));
        }

        /// <inheritdoc />
        protected internal override string ElementName
        {
            get { return FbmlConstants.FB_IF_IS_APP_USER; }
        }
    }
}
